<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('福利补缴登记')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: bootstrap-editable-css"/>

</head>
<style>
    .fixed-table-container .bs-checkbox .th-inner {
        padding: 8px 8px !important;
    }
</style>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <input type="hidden" name="allId" id="allId"/>
                <div class="select-list">
                    <ul>
                        <li>
                            <p>工号：</p>
                            <input type="text" name="badge"/>
                        </li>
                        <li>
                            <p>姓名：</p>
                            <input type="text" name="name"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:benefitbase:add">
                <i class="fa fa-plus"></i> 添加员工
            </a>
            <a class="btn btn-danger" onclick="inspect('cSP_BeneSupplyDec')"
               shiro:hasPermission="system:benefitbase:remove">
                <i class="fa fa-remove"></i> 删除记录
            </a>

            <a class="btn btn-primary" onclick="inspect('cSP_BeneSupplyCheck')"
               shiro:hasPermission="system:welfareopen:edit">
                <i class="fa fa-edit"></i> 确认检查
            </a>
            <a class="btn btn-danger" onclick="inspect('cSP_BeneSupplyCancel')"
               shiro:hasPermission="system:benefitbase:remove">
                <i class="fa fa-remove"></i> 取消确认
            </a>

            <a class="btn btn-warning" onclick="inspect('cSP_BeneSupplyStart')" shiro:hasPermission="system:benefitbase:export">
                <i class="fa fa-download"></i> 变动处理
            </a>

        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
</body>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: bootstrap-table-editable-js"/>

<th:block th:include="include :: hr-help-js"/>
<th:block th:include="include :: datetimepicker-js"/>
<script th:inline="javascript">
    var prefix = ctx + "welfare/welfarePayment/welfarePaymentRegister";

    function inspect(storage) {
        var allId = "";
        var procedure=storage;
        var row = $("#bootstrap-table").bootstrapTable('getSelections');
        for (var i = 0; i < row.length; i++) {
            if (i == row.length - 1) {
                allId += row[i].id
            } else {
                allId += row[i].id + ","

            }
        }
        if (row.length == 0) {
            $.modal.alertWarning("请选择数据!");
            return;
        } else {
            $.ajax({
                async: false,
                url: prefix + "/procedure",
                data: {
                    allId: allId,
                    procedure: procedure

                },
                type: "post",
                dataType: "json",
                success: function (data) {

                    if (procedure=="cSP_BeneSupplyCheck"&&data.code == 0) {
                        $("#allId").val(allId);
                        $.modal.alertWarning("操作成功!");

                        $("#bootstrap-table").bootstrapTable("refresh");
                    } else if (data.code == 500) {
                        $.modal.alertWarning("服务器繁忙!");
                        $("#bootstrap-table").bootstrapTable("refresh");
                    } else if (data.code == 0) {
                        $.modal.alertWarning("操作成功!");
                        $("#allId").val('');
                        $("#bootstrap-table").bootstrapTable("refresh");
                    }else {
                        $.modal.alertWarning(data.message);
                        $("#bootstrap-table").bootstrapTable("refresh");
                    }
                },

            });
        }
    }
    $(function () {

        add();

    })

    function add() {

        var arry;
        var other;
        var columns = [];
        var checkbox = {checkbox: true};
        var id = {field: 'id', title: '序号'};
        var badge = {field: 'badge', title: '工号'};
        var name = {field: 'name', title: '姓名'};
        var compName = {field: 'compName', title: '公司名称'};
        var depName = {field: 'depName', title: '部门名称'};
        var jobName = {field: 'jobName', title: '工作岗位'};
        var benefitStatus = {field: 'benefitStatus', title: '社保缴纳'};
        var benefitCity = {field: 'benefitCity', title: '社保缴纳地区'};
        var accuCity = {field: 'accuCity', title: '公积金缴纳地区'};
        var effectDate = {
            field: 'effectDate',
            title: '补缴月份',
            editable: {
                type: 'date',
                clear: false,
                placement: 'left',//位置
                emptytext: "请选择日期",//默认值
                datepicker: {
                    language: 'zh-CN',//中文支持
                },

            }


        };

        var SupplyMonths = {
            field: 'SupplyMonths', title: '补缴月数',
            editable: {
                emptytext: "请选择补缴月数",//默认值

            }
        };
        var remark = {
            field: 'remark', title: '备注',
            editable: {
                emptytext: "--",//默认值

            }
        };
        var regbyName = {field: 'regbyName', title: '登记人'};
        var regTime = {field: 'regTime', title: '登记时间'};
        var initialized = {
            field: 'initialized',
            title: '？确认',
            formatter: function (value, row, index) {
                if (row.initialized == 1) {
                    return '<i class=\"fa fa-toggle-on text-info fa-2x\" ></i> ';
                } else {
                    return '<i class=\"fa fa-toggle-off text-info fa-2x\" ></i> ';
                }
            }
        };
        var initializedbyName = {field: 'initializedbyName', title: '确认人'};
        var initializedtime = {field: 'initializedtime', title: '确认时间'};
        columns.push(checkbox, id, badge, name, compName, depName, jobName, benefitStatus, benefitCity, accuCity, effectDate, SupplyMonths, remark, regbyName, regTime, initialized, initializedbyName, initializedtime);
        $.ajax({
            async: false,
            url: prefix + "/findHeader",
            data: {},
            type: "post",
            dataType: "json",
            success: function (data) {

                for (var i = 0; i < data.length; i++) {
                    other = {
                        field: data[i].field, title: data[i].title, editable: {
                            emptytext: '-',

                        }
                    }
                    columns.push(other);
                }


                var options = {
                    code: "id",
                    uniqueId: "id",
                    url: prefix + '/list',
                    height: $(window).height() - 120,
                    createUrl: prefix + "/add",
                    pagination : false,
                    modalName: "福利缴纳变动",
                    onEditableSave: onEditableSave,
                    columns: columns
                };
                $.table.init(options);


            },


        });


    }

    (function ($) {
        $.fn.datepicker.dates['zh-CN'] = {
            days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
            daysShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
            daysMin: ["日", "一", "二", "三", "四", "五", "六"],
            months: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
            monthsShort: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
            today: "今天",
            monthsTitle: "选择月份",
            clear: "清除",
            format: "yyyy-mm-dd",
            titleFormat: "yyyy年mm月",
            weekStart: 1
        };
    }(jQuery));

    function onEditableSave(field, row, oldValue, $el) {
        var id = row.id;
        var field = field;
        var value = row[field];


        $.ajax({
            url: prefix + "/edit",
            data: {
                id: id,
                field: field,
                value: value
            },
            type: "post",
            dataType: "json",
            success: function (data) {
                if (data.code == 0) {
                    $.modal.alertWarning("操作成功！");
                    $("#bootstrap-table").bootstrapTable("refresh");
                } else if (data.code == 500) {
                    $.modal.alertWarning("服务器繁忙！");
                    $("#bootstrap-table").bootstrapTable("refresh");
                } else {
                    $.modal.alertWarning(data.message);
                    $("#bootstrap-table").bootstrapTable("refresh");
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });

    }


</script>
</html>